function success(res, data={}, msg, statusCode=200) {
  res.status(statusCode).json({
    msg,
    data,
    code: 0
  });
}

function fail(res, err) {
  if(err.name === 'SequelizeValidationError'){
    return res.status(400).json({
      msg: err.errors.map(e => e.message).join(','),
      data: null,
      code: 1
    });
  }
  if(err.name === 'NotFoundError'){
    return res.status(404).json({
      msg: err.message,
      data: null,
      code: 1
    });
  }
  res.status(500).json({
    msg: err.message,
    data: null,
    code: 1
  });
}

module.exports = {
  success,
  fail
}